package com.simba.server.commands.impl.web;

import com.simba.common.command.ICommand;
import com.simba.server.components.SorterParams;
import com.simba.server.components.data.ResultInfo;
import org.apache.log4j.Logger;


import com.simba.common.log.LogUtil;
import com.simba.server.ServerParam;

import com.simba.server.components.data.MachineRunInfo;
import com.simba.server.webservice.WebServiceManager;

/**
 * 包分机状态回传
 */
public class WebBFJStatusCmd implements ICommand
{
	public static final String NAME = "WebBFJStatusCmd";
	private static final Logger logger = Logger.getLogger(WebBFJStatusCmd.class);
	private final MachineRunInfo info;

	public WebBFJStatusCmd(MachineRunInfo info)
	{
		this.info = info;
	}

	@Override
	public String getName()
	{
		return WebBFJStatusCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		if (info == null)
		{
			return false;
		}
		boolean ret = false;
		String remoteMethod = "";
		String content = "";
		try
		{
			if (SorterParams.getInstance().isDebugMode()){
				LogUtil.LogError(logger, "upload BFJ state error: debug mode doesn't upload data!");
				return false;
			}

			ResultInfo response = WebServiceManager.getInstance().doNothing(ServerParam.REMOTE_WEBSERVICE_ADDRESS, remoteMethod, content);
			if (response != null)
			{
				ret = this.handleResponse(response);
			}
		}
		catch (Exception e)
		{
			LogUtil.LogError(WebBFJStatusCmd.logger, "upload BFJ state error: " + e);
			ret = false;

		}
		return ret;
	}

	private boolean handleResponse(ResultInfo response)
	{
		boolean ret = false;
		try
		{
			ret = true;
		}
		catch (Exception e)
		{
			LogUtil.LogError(WebBFJStatusCmd.logger, "parse bfj status result failed : " + e);
		}
		return ret;
	}
}
